/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package central;

import giovynet.nativelink.SerialPort;
import giovynet.serial.Baud;
import giovynet.serial.Com;
import giovynet.serial.Parameters;
import java.util.List;

/**
 *
 * @author agustin
 */
public class Capturador {

    static SerialPort puerto = new SerialPort();
    static List<String> listaPuertos;
    static Com com;
    private static Capturador instancia;

    private Capturador() {
    }

    public static Capturador getInstancia() {
        if (instancia == null) {
            instancia = new Capturador();
        }
        return instancia;

    }

    public void capturador(String puertoX, Baud baudios) throws Exception {
        listaPuertos = puerto.getFreeSerialPort();
        String recibido = "";
        String caracter = "";
        for (String string : listaPuertos) {
            System.out.print(string);
        }
        Parameters settings = new Parameters();
        settings.setPort(puertoX);
        settings.setBaudRate(baudios);
        com = new Com(settings);
        while (1 != 2) {
            while (!caracter.equals("\n")) {
                caracter = com.receiveSingleString();
                recibido += caracter;
                System.out.println(caracter);
            }
            if (!recibido.equals("")) {
                Guardar.getInstance().persistirCapturas(recibido);
                System.out.print(recibido);
                recibido = "";
                caracter = "";
            }
        }
    }
}
